#include "v3d.h"
#include <math.h>



    v3d::v3d()
    {
        x=0;
        y=0;
        z=0;
    }

    v3d & v3d::operator = (cl_float4 &f)
    {
        x=f.x;
        y=f.y;
        z=f.z;
        return *this;
    }

    v3d::v3d (double px, double py, double pz)
    {
        x=px, y=py, z=pz;
    }

    v3d & v3d::operator()(double px, double py, double pz)
    {
        x=px, y=py, z=pz;

        return *this;

    }

    v3d v3d::operator * (double other)
    {
        v3d herp;
        herp(this->x*other, this->y*other, this->z*other);
        return herp;
    }

    v3d & v3d::operator+=(v3d &other)
    {
        x+=other.x;
        y+=other.y;
        z+=other.z;
        return *this;
    }

    v3d & v3d::operator-=(v3d &other)
    {
        x-=other.x;
        y-=other.y;
        z-=other.z;
        return *this;

    }

    v3d & v3d::operator/=(v3d &other)
    {
        x/=other.x;
        y/=other.y;
        z/=other.z;
        return *this;

    }

    v3d & v3d::operator/=(double other)
    {
        x/=other;
        y/=other;
        z/=other;
        return *this;

    }

    v3d v3d::operator + (v3d &other)
    {
        v3d herp;
        herp(other.x+this->x, other.y+this->y, other.z+this->z);
        return herp;
    }

    v3d v3d::operator - (v3d&other)
    {
        v3d herp;
        herp(this->x-other.x, this->y-other.y, this->z-other.z);
        return herp;
    }

    v3d v3d::operator / (double value)
    {
        v3d herp;
        herp(this->x/value, this->y/value, this->z/value);
        return herp;
    }

    v3d v3d::operator * (v3d&o)
    {
        v3d herp;
        herp(this->x*o.x, this->y*o.y, this->z*o.z);
        return herp;
    }

    double v3d::magnitude()
    {
           return sqrt(x*x+y*y+z*z);
    }

    v3d v3d::operator -()
    {
        v3d herp;
        herp(-this->x, -this->y, -this->z);
        return herp;
    }

    v3d v3d::normalise()
    {
        v3d herp;
        herp(this->x/this->magnitude(), this->y/this->magnitude(), this->z/this->magnitude());
        return herp;
    }

    v3d v3d::abs()
    {
        v3d herp;
        herp(fabs(this->x), fabs(this->y), fabs(this->z));
        return herp;

    }
